package com.ruoyi.project.management.tranfer.service;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.management.delay.mapper.ManagementTaskMapper;
import com.ruoyi.project.management.tranfer.domain.TaskTransfer;
import com.ruoyi.project.management.tranfer.mapper.ManagementTransferMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ManagementTransferServiceImpl implements ManagementTransferService {

    @Autowired
    private ManagementTransferMapper managementTransferMapper;

    /*@Autowired
    private ManagementTaskMapper managementTaskMapper;*/


    @Override
    public List<TaskTransfer> selectAll(TaskTransfer taskTransfer) {
        return managementTransferMapper.selectAll(taskTransfer);
    }

    @Override
    public Integer insert(TaskTransfer taskTransfer) {
        return managementTransferMapper.insert(taskTransfer);
    }

    @Override
    public TaskTransfer selectById(Integer transfer_id) {
        return managementTransferMapper.selectById(transfer_id);
    }

    @Override
    @Transactional
    public Integer update(TaskTransfer taskTransfer) {
       // taskTransfer.setCreateBy(ShiroUtils.getLoginName());
        /*if(taskTransfer.getPass() == 1 && taskTransfer.getSuccessor() != null){
            System.out.println("+++++++++++++++++++Yes++++++++++++++++++");
            //当审核通过并且存在接替人时修改接替者为任务执行人
            managementTaskMapper.updateByExecutor(taskTransfer.getSuccessor(),taskTransfer.getTask_id());
        }
        ShiroUtils.clearCachedAuthorizationInfo();*/
        return managementTransferMapper.update(taskTransfer);
    }

    @Override
    public int delete(String ids) {

        Long[] taskIDs = Convert.toLongArray(ids);
        return managementTransferMapper.delete(taskIDs);
    }
}
